#!/usr/bin/env python
"""
Acorn-SDR (A Collaboration of Radio Nodes)
(c) Bob Cowdery (G3UKB) 2009

File: gtk_mini_gui.py
Date: April 2009

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

The author can be reached by email at

bob@g3ukb.co.uk

========================================================================
Module Description:

The option panels.

"""

#-----------------------------------------------------------------------
# System imports
import sys
from time import sleep

# Import GTK libraries
import pygtk
import gtk
import gtk.glade
import gobject

# Application imports
import utils

# Lookups for converting index to stored values and vica versa
rates_to_index = {48000.0:0,96000.0:1,192000.0:2}
index_to_rates = {0:48000.0,1:96000.0,2:192000.0}
frames_to_index = {64:0,128:1,256:2,512:3,1024:4}
index_to_frames = {0:64,1:128,2:256,3:512,4:1024}
output_to_index = {'mercury':0,'janus':1,'soundcard':2,'mercury+soundcard':3,'janus+soundcard':4}
index_to_output = {0:'mercury',1:'janus',2:'soundcard',3:'mercury+soundcard',4:'janus+soundcard'}
periods_to_index = {2:0,4:1,6:2,8:3,10:4,12:5,14:6,16:7}
index_to_periods = {0:2,1:4,2:6,3:8,4:10,5:12,6:14,7:16}
pp_to_index = {0x278:0,0x378:1}
index_to_pp = {0:0x278,1:0x378}
ref_to_index = {'atlas':0,'penelope':1,'mercury':2}
index_to_ref = {0:'atlas',1:'penelope',2:'mercury'}
source_to_index = {'penelope':0,'mercury':1}
index_to_source = {0:'penelope',1:'mercury'}
config_to_index = {'none':0,'penelope':1,'mercury':2,'penelope&mercury':3}
index_to_config = {0:'none',1:'penelope',2:'mercury',3:'penelope&mercury'}
mic_to_index = {'janus':0,'penelope':1}
index_to_mic = {0:'janus',1:'penelope'}

#=========================================================================
# The Options GUI class.
class OptionsGui:
  
    #---------------------------------------------------------------------
    def __init__(self, main_tree, persist_service):
        self.main_tree = main_tree
        self.persist_service = persist_service
        self.ignore = False
        
        #-----------------------------------------------------------------------
        # Wire up the events
        dic =   {
                'on_fc_path_glade_file_set'                 : self.path_glade,
                'on_fc_path_iceconfig_file_set'             : self.path_iceconfig,
                
                'on_cb_audio_rate_changed'                  : self.audio_rate_changed,
                'on_cb_audio_frames_changed'                : self.audio_frames_changed,
                'on_cb_audio_output_changed'                : self.audio_output_changed,
                'on_tb_audio_output_fixed_toggled'          : self.audio_output_fixed_toggled,
                
                'on_cb_jack_periods_changed'                : self.jack_periods_changed,
                'on_e_jack_in_ch1_changed'                  : self.jack_in_ch1_changed,
                'on_e_jack_in_ch2_changed'                  : self.jack_in_ch2_changed,
                'on_e_jack_out_ch1_changed'                 : self.jack_out_ch1_changed,
                'on_e_jack_out_ch2_changed'                 : self.jack_out_ch2_changed,
                
                'on_tb_sdr1k_rfe_toggled'                   : self.sdr1k_rfe_toggled,
                'on_tb_sdr1k_pa_toggled'                    : self.sdr1k_pa_toggled,
                'on_tb_sdr1k_usb_toggled'                   : self.sdr1k_usb_toggled,
                'on_cb_sdr1k_pp_changed'                    : self.sdr1k_pp_changed,
                
                'on_cb_hpsdr_ref_changed'                   : self.hpsdr_ref_changed,
                'on_cb_hpsdr_source_changed'                : self.hpsdr_source_changed,
                'on_cb_hpsdr_board_config_changed'          : self.hpsdr_board_config_changed,
                'on_cb_hpsdr_mic_source_changed'            : self.hpsdr_mic_source_changed,
                
                'on_sb_dsp_ramp_value_changed'              : self.dsp_agc_ramp_changed,
                'on_sb_dsp_gain_value_changed'              : self.dsp_agc_gain_changed,
                'on_sb_dsp_roof_value_changed'              : self.dsp_agc_roof_changed,
                
                'on_e_processes_changed'                    : self.processes_changed,
                'on_tb_startjack_toggled'                   : self.startjack_toggled,
                'on_e_console_changed'                      : self.console_changed,
                'on_e_dsp_changed'                          : self.dsp_changed,
                'on_e_jackin_changed'                       : self.jackin_changed,
                'on_e_jackout_changed'                      : self.jackout_changed,
                'on_e_ozy_changed'                          : self.ozy_changed,
                'on_e_hwif_changed'                         : self.hwif_changed,
                'on_e_ozydsp_changed'                       : self.ozydsp_changed,
                
                'on_hs_disp_level_value_changed'            : self.disp_level_changed,
                }  
        # This will connect up all the events in one hit
        self.main_tree.signal_autoconnect (dic)

        #-----------------------------------------------------------------------
        # Now we need a reference to all the controls
        # A bit long winded but easy to follow
        # All controls in the tree must have a unique name
        self.path_glade = self.main_tree.get_widget('fc_path_glade')
        self.path_iceconfig = self.main_tree.get_widget('fc_path_iceconfig')
        
        self.audio_rate = self.main_tree.get_widget('cb_audio_rate')
        self.audio_frames = self.main_tree.get_widget('cb_audio_frames')
        self.audio_output = self.main_tree.get_widget('cb_audio_output')
        
        self.jack_periods = self.main_tree.get_widget('cb_jack_periods')
        self.jack_in_ch1 = self.main_tree.get_widget('e_jack_in_ch1')
        self.jack_in_ch2 = self.main_tree.get_widget('e_jack_in_ch2')
        self.jack_out_ch1 = self.main_tree.get_widget('e_jack_out_ch1')
        self.jack_out_ch2 = self.main_tree.get_widget('e_jack_out_ch2')
        
        self.sdr1k_rfe = self.main_tree.get_widget('tb_sdr1k_rfe')
        self.sdr1k_pa = self.main_tree.get_widget('tb_sdr1k_pa')
        self.sdr1k_usb = self.main_tree.get_widget('tb_sdr1k_usb')
        self.sdr1k_pp = self.main_tree.get_widget('cb_sdr1k_pp')
        
        self.hpsdr_ref = self.main_tree.get_widget('cb_hpsdr_ref')
        self.hpsdr_source = self.main_tree.get_widget('cb_hpsdr_source')
        self.hpsdr_board_config = self.main_tree.get_widget('cb_hpsdr_board_config')
        self.hpsdr_mic_source = self.main_tree.get_widget('cb_hpsdr_mic_source')
        
        self.dsp_ramp = self.main_tree.get_widget('sb_dsp_ramp')
        self.dsp_gain = self.main_tree.get_widget('sb_dsp_gain')
        self.dsp_roof = self.main_tree.get_widget('sb_dsp_roof')
        
        self.processes = self.main_tree.get_widget('e_processes')
        self.startjack = self.main_tree.get_widget('tb_startjack')
        self.console = self.main_tree.get_widget('e_console')
        self.dsp = self.main_tree.get_widget('e_dsp')
        self.jackin = self.main_tree.get_widget('e_jackin')
        self.jackout = self.main_tree.get_widget('e_jackout')
        self.ozy = self.main_tree.get_widget('e_ozy')
        self.hwif = self.main_tree.get_widget('e_hwif')
        self.ozydsp = self.main_tree.get_widget('e_ozydsp')
        
        self.disp_level = self.main_tree.get_widget('hs_disp_level')
    
        #-----------------------------------------------------------------------
        # Initialise all controls from the persistence service
        self.update('all')
            
    #===========================================================================
    # UI Events
    #===========================================================================
    # Paths
    #---------------------------------------------------------------------------
    def path_glade(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.glade', widget.get_filename())
    
    #---------------------------------------------------------------------------
    def path_iceconfig(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.iceconfig', widget.get_filename())
    
    #===========================================================================
    # Audio
    #---------------------------------------------------------------------------
    def audio_rate_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'audio.rate', index_to_rates[index])
        except:
            pass
        
    #---------------------------------------------------------------------------
    def audio_frames_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'audio.frames', index_to_frames[index])
        except:
            pass
        
    #---------------------------------------------------------------------------
    def audio_output_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'audio.output', index_to_output[index])
        except:
            pass
     
    #---------------------------------------------------------------------------   
    def audio_output_fixed_toggled(self, widget):
        if self.ignore: return
        if widget.get_active():
            active = True
            widget.set_label('Yes')
        else:
            active = False
            widget.set_label('No')
        utils.persist_put(self.persist_service, 'Profile', 'audio.outputfixed', active)
        
    #===========================================================================
    # Jack
    #---------------------------------------------------------------------------
    def jack_periods_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'jack.periods', index_to_periods[index])
        except:
            pass

    #---------------------------------------------------------------------------
    def jack_in_ch1_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'jack.indevch1', widget.get_text())
        
    #---------------------------------------------------------------------------
    def jack_in_ch2_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'jack.indevch2', widget.get_text())
        
    #---------------------------------------------------------------------------
    def jack_out_ch1_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'jack.outdevch1', widget.get_text())
        
    #---------------------------------------------------------------------------
    def jack_out_ch2_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'jack.outdevch1', widget.get_text())
                
    #===========================================================================
    # SDR1000
    #---------------------------------------------------------------------------
    def sdr1k_rfe_toggled(self, widget):
        if self.ignore: return
        if widget.get_active():
            active = True
            widget.set_label('Yes')
        else:
            active = False
            widget.set_label('No')
        utils.persist_put(self.persist_service, 'Profile', 'sdr1k.rfe', active)

    #---------------------------------------------------------------------------
    def sdr1k_pa_toggled(self, widget):
        if self.ignore: return
        if widget.get_active():
            active = True
            widget.set_label('Yes')
        else:
            active = False
            widget.set_label('No')
        utils.persist_put(self.persist_service, 'Profile', 'sdr1k.pa', active)
    
    #---------------------------------------------------------------------------
    def sdr1k_usb_toggled(self, widget):
        if self.ignore: return
        if widget.get_active():
            active = True
            widget.set_label('Yes')
        else:
            active = False
            widget.set_label('No')
        utils.persist_put(self.persist_service, 'Profile', 'sdr1k.usb', active)
    
    #---------------------------------------------------------------------------
    def sdr1k_pp_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'sdr1k.ppaddr', index_to_pp[index])
        except:
            pass
    
    #===========================================================================
    # HPSDR
    #---------------------------------------------------------------------------
    def hpsdr_ref_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'hpsdr.ref', index_to_ref[index])
        except:
            pass
        
    #---------------------------------------------------------------------------
    def hpsdr_source_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'hpsdr.src', index_to_source[index])
        except:
            pass
        
    #---------------------------------------------------------------------------
    def hpsdr_board_config_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'hpsdr.config', index_to_config[index])
        except:
            pass
    
    #---------------------------------------------------------------------------
    def hpsdr_mic_source_changed(self, widget):
        if self.ignore: return
        index = widget.get_active()
        try:  
            utils.persist_put(self.persist_service, 'Profile', 'hpsdr.mic', index_to_mic[index])
        except:
            pass
        
    #===========================================================================
    # DSP
    #---------------------------------------------------------------------------
    def dsp_agc_ramp_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'dsp.agcramp', widget.get_value())
    
    #---------------------------------------------------------------------------
    def dsp_agc_gain_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'dsp.agcgain', widget.get_value())
    
    #---------------------------------------------------------------------------
    def dsp_agc_roof_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'dsp.agcroof', widget.get_value())
    
    #===========================================================================
    # Processes
    #---------------------------------------------------------------------------
    def processes_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.processes', widget.get_text())
        
    #---------------------------------------------------------------------------
    def startjack_toggled(self, widget):
        if self.ignore: return
        if widget.get_active():
            active = True
            widget.set_label('Yes')
        else:
            active = False
            widget.set_label('No')
        utils.persist_put(self.persist_service, 'Profile', 'jack.load', active)
        
    #---------------------------------------------------------------------------
    def console_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.DEFAULT_GUI', widget.get_text())
        
    #---------------------------------------------------------------------------
    def dsp_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.PY_DSP', widget.get_text())
        
    #---------------------------------------------------------------------------
    def jackin_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.JACK_IN', widget.get_text())
        
    #---------------------------------------------------------------------------
    def jackout_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.JACK_OUT', widget.get_text())
        
    #---------------------------------------------------------------------------
    def ozy_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.OZY', widget.get_text())
        
    #---------------------------------------------------------------------------
    def hwif_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.HW_CONT', widget.get_text())
    
    #---------------------------------------------------------------------------
    def ozydsp_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'path.OZY+PY_DSP', widget.get_text())
     
    #===========================================================================
    # Calibration   
    def disp_level_changed(self, widget):
        if self.ignore: return
        utils.persist_put(self.persist_service, 'Profile', 'calib.display_level', widget.get_value())
        
    #===========================================================================
    # Control updates
    #===========================================================================
    
    #---------------------------------------------------------------------------
    def set_path_glade(self):
        self.path_glade.set_filename(utils.persist_get(self.persist_service, 'Profile', 'path.glade'))
        
    #---------------------------------------------------------------------------
    def set_path_iceconfig(self):
        self.path_iceconfig.set_filename(utils.persist_get(self.persist_service, 'Profile', 'path.iceconfig'))
        
    #---------------------------------------------------------------------------
    def set_audio_rate(self):
        rate = utils.persist_get(self.persist_service, 'Profile', 'audio.rate')
        if rate <> 'Empty':
            self.audio_rate.set_sensitive(True)
            self.audio_rate.set_active(rates_to_index[rate])
        else:
            self.audio_rate.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_audio_frames(self):
        frames = utils.persist_get(self.persist_service, 'Profile', 'audio.frames')
        if frames <> 'Empty':
            self.audio_frames.set_sensitive(True)
            self.audio_frames.set_active(frames_to_index[frames])
        else:
            self.audio_frames.set_sensitive(False)
    
    #---------------------------------------------------------------------------
    def set_audio_output(self):
        output = utils.persist_get(self.persist_service, 'Profile', 'audio.output')
        if output <> 'Empty':
            self.audio_output.set_sensitive(True)
            self.audio_output.set_active(output_to_index[output])
        else:
            self.audio_output.set_sensitive(False)
    
    #---------------------------------------------------------------------------
    def set_jack_periods(self):
        periods = utils.persist_get(self.persist_service, 'Profile', 'jack.periods')
        if periods <> 'Empty':
            self.jack_periods.set_sensitive(True)
            self.jack_periods.set_active(periods_to_index[periods])
        else:
            self.jack_periods.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_jack_indevch1(self):
        ch = utils.persist_get(self.persist_service, 'Profile', 'jack.indevch1')
        if ch <> 'Empty':
            self.jack_in_ch1.set_sensitive(True)
            self.jack_in_ch1.set_text(ch)
        else:
            self.jack_in_ch1.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_jack_indevch2(self):
        ch = utils.persist_get(self.persist_service, 'Profile', 'jack.indevch2')
        if ch <> 'Empty':
            self.jack_in_ch2.set_sensitive(True)
            self.jack_in_ch2.set_text(ch)
        else:
            self.jack_in_ch2.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_jack_outdevch1(self):
        ch = utils.persist_get(self.persist_service, 'Profile', 'jack.outdevch1')
        if ch <> 'Empty':
            self.jack_out_ch1.set_sensitive(True)
            self.jack_out_ch1.set_text(ch)
        else:
            self.jack_out_ch1.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_jack_outdevch2(self):
        ch = utils.persist_get(self.persist_service, 'Profile', 'jack.outdevch2')
        if ch <> 'Empty':
            self.jack_out_ch2.set_sensitive(True)
            self.jack_out_ch2.set_text(ch)
        else:
            self.jack_out_ch2.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_sdr1k_rfe(self):
        active = utils.persist_get(self.persist_service, 'Profile', 'sdr1k.rfe')
        if active <> 'Empty':
            self.sdr1k_rfe.set_sensitive(True)
            self.sdr1k_rfe.set_active(active)
            if active:
                self.sdr1k_rfe.set_label('Yes')
            else:
                self.sdr1k_rfe.set_label('No')
        else:
            self.sdr1k_rfe.set_sensitive(False)
          
    #---------------------------------------------------------------------------
    def set_sdr1k_pa(self):  
        active = utils.persist_get(self.persist_service, 'Profile', 'sdr1k.pa')
        if active <> 'Empty':
            self.sdr1k_pa.set_sensitive(True)
            self.sdr1k_pa.set_active(active)
            if active:
                self.sdr1k_pa.set_label('Yes')
            else:
                self.sdr1k_pa.set_label('No')
        else:
            self.sdr1k_pa.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_sdr1k_usb(self):
        active = utils.persist_get(self.persist_service, 'Profile', 'sdr1k.usb')
        if active <> 'Empty':
            self.sdr1k_usb.set_sensitive(True)
            self.sdr1k_usb.set_active(active)
            if active:
                self.sdr1k_usb.set_label('Yes')
            else:
                self.sdr1k_usb.set_label('No')
        else:
            self.sdr1k_usb.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_sdr1k_ppaddr(self):
        pp = utils.persist_get(self.persist_service, 'Profile', 'sdr1k.ppaddr')
        if pp  <> 'Empty':
            self.sdr1k_pp.set_sensitive(True)
            self.sdr1k_pp.set_active(pp_to_index[pp])
        else:
            self.sdr1k_pp.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_hpsdr_ref(self):
        ref = utils.persist_get(self.persist_service, 'Profile', 'hpsdr.ref')
        if ref  <> 'Empty':
            self.hpsdr_ref.set_sensitive(True)
            self.hpsdr_ref.set_active(ref_to_index[ref])
        else:
            self.hpsdr_ref.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_hpsdr_src(self):
        src = utils.persist_get(self.persist_service, 'Profile', 'hpsdr.src')
        if src  <> 'Empty':
            self.hpsdr_source.set_sensitive(True)
            self.hpsdr_source.set_active(source_to_index[src])
        else:
            self.hpsdr_source.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_hpsdr_config(self):
        config = utils.persist_get(self.persist_service, 'Profile', 'hpsdr.config')
        if config  <> 'Empty':
            self.hpsdr_board_config.set_sensitive(True)
            self.hpsdr_board_config.set_active(config_to_index[config])
        else:
            self.hpsdr_board_config.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_hpsdr_mic(self):
        mic = utils.persist_get(self.persist_service, 'Profile', 'hpsdr.mic')
        if mic  <> 'Empty':
            self.hpsdr_mic_source.set_sensitive(True)
            self.hpsdr_mic_source.set_active(mic_to_index[mic])
        else:
            self.hpsdr_mic_source.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_dsp_agcramp(self):
        ramp = utils.persist_get(self.persist_service, 'Profile', 'dsp.agcramp')
        if ramp  <> 'Empty':
            self.dsp_ramp.set_sensitive(True)
            self.dsp_ramp.set_value(ramp)
        else:
            self.dsp_ramp.set_sensitive(False)
        
    #---------------------------------------------------------------------------
    def set_dsp_agcgain(self):
        gain = utils.persist_get(self.persist_service, 'Profile', 'dsp.agcgain')
        if gain  <> 'Empty':
            self.dsp_gain.set_sensitive(True)
            self.dsp_gain.set_value(gain)
        else:
            self.dsp_gain.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_dsp_agcroof(self):
        roof = utils.persist_get(self.persist_service, 'Profile', 'dsp.agcroof')
        if roof  <> 'Empty':
            self.dsp_roof.set_sensitive(True)
            self.dsp_roof.set_value(roof)
        else:
            self.dsp_roof.set_sensitive(False)
 
    #---------------------------------------------------------------------------
    def set_processes(self):
        procs = utils.persist_get(self.persist_service, 'Profile', 'processes')
        if procs <> 'Empty':
            self.processes.set_sensitive(True)
            self.processes.set_text(procs)
        else:
            self.processes.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_startjack(self):
        active = utils.persist_get(self.persist_service, 'Profile', 'jack.load')
        if active <> 'Empty':
            self.startjack.set_sensitive(True)
            self.startjack.set_active(active)
            if active:
                self.startjack.set_label('Yes')
            else:
                self.startjack.set_label('No')
        else:
            self.startjack.set_sensitive(False)
            
    #------------------------------------------------------------------
    def set_default_gui(self):
        console = utils.persist_get(self.persist_service, 'Profile', 'path.DEFAULT_GUI')
        if console <> 'Empty':
            self.console.set_sensitive(True)
            self.console.set_text(console)
        else:
            self.console.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_py_dsp(self):
        dsp = utils.persist_get(self.persist_service, 'Profile', 'path.PY_DSP')
        if dsp <> 'Empty':
            self.dsp.set_sensitive(True)
            self.dsp.set_text(dsp)
        else:
            self.dsp.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_jack_in(self):
        inp = utils.persist_get(self.persist_service, 'Profile', 'path.JACK_IN')
        if inp <> 'Empty':
            self.jackin.set_sensitive(True)
            self.jackin.set_text(inp)
        else:
            self.jackin.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_jack_out(self):
        out = utils.persist_get(self.persist_service, 'Profile', 'path.JACK_OUT')
        if out <> 'Empty':
            self.jackout.set_sensitive(True)
            self.jackout.set_text(out)
        else:
            self.jackout.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_ozy(self):
        oz = utils.persist_get(self.persist_service, 'Profile', 'path.OZY')
        if oz <> 'Empty':
            self.ozy.set_sensitive(True)
            self.ozy.set_text(oz)
        else:
            self.ozy.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_hw_cont(self):
        hwif = utils.persist_get(self.persist_service, 'Profile', 'path.HW_CONT')
        if hwif <> 'Empty':
            self.hwif.set_sensitive(True)
            self.hwif.set_text(hwif)
        else:
            self.hwif.set_sensitive(False)
            
    #---------------------------------------------------------------------------
    def set_ozydsp(self):
        ozdsp = utils.persist_get(self.persist_service, 'Profile', 'path.OZY+PY_DSP')
        if ozdsp <> 'Empty':
            self.ozydsp.set_sensitive(True)
            self.ozydsp.set_text(ozdsp)
        else:
            self.ozydsp.set_sensitive(False)
     
    #---------------------------------------------------------------------------
    def set_disp_calib(self):
        disp_level = utils.persist_get(self.persist_service, 'Profile', 'calib.display_level')
        if disp_level <> 'Empty':
            self.disp_level.set_sensitive(True)
            self.disp_level.set_value(disp_level)
        else:
            self.disp_level.set_sensitive(False)
            
    # Dictionary to call updaters
    #---------------------------------------------------------------------------
    def update(self, what):
        update_list = {
            'path.glade': self.set_path_glade,
            'path.iceconfig': self.set_path_iceconfig,
            'audio.rate': self.set_audio_rate,
            'audio.frames': self.set_audio_frames,
            'audio.output':self.set_audio_output,
            'jack.periods': self.set_jack_periods,
            'jack.indevch1': self.set_jack_indevch1,
            'jack.indevch2': self.set_jack_indevch2,
            'jack.outdevch1': self.set_jack_outdevch1,
            'jack.outdevch2': self.set_jack_outdevch2,
            'sdr1k.rfe': self.set_sdr1k_rfe,
            'sdr1k.pa': self.set_sdr1k_pa,
            'sdr1k.usb': self.set_sdr1k_usb,
            'sdr1k.ppaddr': self.set_sdr1k_ppaddr,
            'hpsdr.ref': self.set_hpsdr_ref,
            'hpsdr.src': self.set_hpsdr_src,
            'hpsdr.config': self.set_hpsdr_config,
            'hpsdr.mic': self.set_hpsdr_mic,
            'dsp.agcramp': self.set_dsp_agcramp,
            'dsp.agcgain': self.set_dsp_agcgain,
            'dsp.agcroof': self.set_dsp_agcroof,
            'processes': self.set_processes,
            'jack.load': self.set_startjack,
            'path.DEFAULT_GUI': self.set_default_gui,
            'path.PY_DSP': self.set_py_dsp,
            'path.JACK_IN': self.set_jack_in,
            'path.JACK_OUT': self.set_jack_out,
            'path.OZY': self.set_ozy,
            'path.HW_CONT': self.set_hw_cont,
            'path.OZY+PY_DSP': self.set_ozydsp,
            'calib.display_level': self.set_disp_calib,
        }
       
        self.ignore = True
        if what == 'all':
            for updater in update_list.values():
                updater()
        else:
            if what in update_list:
                update_list[what]()
        self.ignore = False
